package com.ruoyi.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.indexLineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.OrderManageMapper;
import com.ruoyi.system.domain.OrderManage;
import com.ruoyi.system.service.IOrderManageService;

/**
 * 订单管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-04-05
 */
@Service
public class OrderManageServiceImpl implements IOrderManageService 
{
    @Autowired
    private OrderManageMapper orderManageMapper;

    /**
     * 查询订单管理
     * 
     * @param id 订单管理主键
     * @return 订单管理
     */
    @Override
    public OrderManage selectOrderManageById(Long id)
    {
        return orderManageMapper.selectOrderManageById(id);
    }

    /**
     * 查询订单管理列表
     * 
     * @param orderManage 订单管理
     * @return 订单管理
     */
    @Override
    public List<OrderManage> selectOrderManageList(OrderManage orderManage)
    {
        return orderManageMapper.selectOrderManageList(orderManage);
    }

    /**
     * 新增订单管理
     * 
     * @param orderManage 订单管理
     * @return 结果
     */
    @Override
    public int insertOrderManage(OrderManage orderManage)
    {
        orderManage.setStatus(1);
        orderManage.setCreateTime(DateUtils.getNowDate());
        return orderManageMapper.insertOrderManage(orderManage);
    }

    /**
     * 修改订单管理
     * 
     * @param orderManage 订单管理
     * @return 结果
     */
    @Override
    public int updateOrderManage(OrderManage orderManage)
    {
        return orderManageMapper.updateOrderManage(orderManage);
    }

    /**
     * 批量删除订单管理
     * 
     * @param ids 需要删除的订单管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderManageByIds(Long[] ids)
    {
        return orderManageMapper.deleteOrderManageByIds(ids);
    }

    /**
     * 删除订单管理信息
     * 
     * @param id 订单管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderManageById(Long id)
    {
        return orderManageMapper.deleteOrderManageById(id);
    }

    @Override
    public int getOrderCount() {
        return orderManageMapper.getOrderCount();
    }

    @Override
    public indexLineVo OrderCountByDay() {
        //订单列表
        ArrayList<Integer> orderList = new ArrayList<>();
        //日期列表
        ArrayList<String> dayList = new ArrayList<>();
        //出货列表
        ArrayList<Integer> accomplishOrderList = new ArrayList<>();
        // 返回的VoList
        indexLineVo indexLineVo = new indexLineVo();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        int x = 0;
        for (int i = 0; i < 7; i++) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(Calendar.DATE, - (x++));//减几就是几天之前
            Date d = calendar.getTime();
            String day = format.format(d);
//            System.out.println("过去七天  ："+day);
            dayList.add(day);
            String day1 = day + " 00:00:00";String day2 = day + " 23:59:59";
            List<OrderManage> orderManages = orderManageMapper.OrderCountByDay(day1, day2);
            List<OrderManage> accomplishOrder = orderManageMapper.accomplishOrder(day1, day2);
            orderList.add(orderManages.size());accomplishOrderList.add(accomplishOrder.size());
        }
        indexLineVo.setFirstData(orderList);indexLineVo.setDateData(dayList);indexLineVo.setSecondData(accomplishOrderList);
        return indexLineVo;
    }
}
